<template>
    <div class="sidebar">  
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="sidebar.collapse"
            background-color="#2f4050"
            text-color="#bfcbd9"
            active-text-color="#fff"
            unique-opened
            router
        >
        <!--  有内容的卡片 -->
        <div v-if="!sidebar.collapse">
        <el-row>
        <el-col>
        <el-card   class="box-card" :body-style="{ padding: '0px' }">
            <el-image style="width:90px; height: 90px" :src="avatarUrl" fit="contain" />
            <div style="padding: 14px;color: #fff;">
                <span>{{ user.userName }}</span>
            </div>
            <div style="padding: 14px">
      
                    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                        <span class="el-dropdown-link">
                            {{ user.userRole}}
                            <el-icon class="el-icon--right">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item command="modifyAvatar">修改头像</el-dropdown-item>
                                <el-dropdown-item command="profile">个人中心</el-dropdown-item>
                                <el-dropdown-item command="contacts">联系我们</el-dropdown-item>
                                <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
            </div>
    
        </el-card>
        </el-col>
  </el-row>
</div>
    <div v-else  class="logo-element">
        <el-row>
    <el-col>
      <el-card   class="box-card01" :body-style="{ padding: '0px' }">
        <div style="padding: 14px;color: #fff;">
            <span>LeMa</span>
        </div>
      </el-card>
    </el-col>
  </el-row>

        
    </div>
    <template v-for="item in menuList">
                <template v-if="item.subMenus"> 
                    <el-sub-menu :index="item.menuUrl+item.id" :key="item.id" v-permiss="item.id">
                        <template #title>
                            <!-- <el-icon>
                                <component :is="item.iconName"></component>
                            </el-icon> -->
                            <i :class="'iconfont '+item.iconName "></i>
                            <span>{{ item.menuName }}</span>
                        </template>
                        <template v-for="subItem in item.subMenus">
                            <el-sub-menu
                                v-if="subItem.subMenus"
                                :index="subItem.menuUrl"
                                :key="subItem.id"
                                v-permiss="subItem.id"
                            >
                                <template #title>{{ subItem.menuName }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subMenus" :key="i" :index="threeItem.menuUrl">
                                    {{ threeItem.menuName }}
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item v-else :index="subItem.menuUrl" v-permiss="subItem.id">
                                <!-- <el-icon>
                                   <component :is="subItem.iconName"></component>
                                 </el-icon> -->
                                 <i class="iconfont icon-big-circle"></i>
                                {{ subItem.menuName }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.menuUrl+item.id" :key="item.id" v-permiss="item.id">
                        <!-- <el-icon>
                            <component :is="item.iconName"></component>
                        </el-icon> -->
                        <el-icon>   <Edit /> </el-icon>
                        <template #title>{{ item.menuName }}</template>
                    </el-menu-item>
                </template>
            </template>

       
        </el-menu>
    </div>
</template>

<script setup >
import { computed,reactive,onMounted} from 'vue';
import { useSidebarStore } from '../stores/sidebar';
import { useMenu } from '../stores/Menu';
import { useRoute ,useRouter} from 'vue-router';
import avatarUrl from '../assets/img/profile.jpg'
const user = reactive({
    userName:'TeacherYe',
    userRole:'超级管理员'
})

const menu  = useMenu();
const menuList  = menu.menuList;
console.log('barmenue>>>',menuList)

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});
const  router = useRouter()
const sidebar = useSidebarStore();

const handleCommand = (command) => {
	if (command == 'loginout') {
        console.log('--------loginout----')
		// localStorage.removeItem('ms_username');
        // localStorage.removeItem('token')
        localStorage.clear()
		router.push('/login');
	} else if (command == 'user') {
		router.push('/user');
	}
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 0px;
    bottom: 0;
    overflow-y: scroll;
    background-color:#2f4050;
}
.sidebar::-webkit-scrollbar {
    width: 0;
  
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 251px;
}
           
.sidebar > ul {
    height: 100%;
}  

/* .avatar {
    background-color:#324157;
    color: #fff;
    padding-left: 20px;
    align-items: center;
    
} */

.el-dropdown-link {
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
}
.el-dropdown-menu__item {
	text-align:center;
}

.box-card{
    background:url('../assets/img/header-profile.png') ;
    border: 0;
    /* padding-left: 20px; */
    padding: 33px 25px;
    width: 250px;
    height: 172px;
}
/* .logo-element {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    display: none;
    padding: 18px 0;
} */
.box-card01{
    text-align: center;
    background:url('../assets/img/header-profile.png') ;
    border: 0;
    height: 50px;  
    color: #fff;
    font-size: 18px;
}
/* .el-menu-item.is-active {
     color: white; 
} */
.iconfont{
    margin-right: 8px;
    font-size: 13px;
}
</style>
